package com.yyds.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyds.yygh.common.result.Result;
import com.yyds.yygh.model.user.UserInfo;
import com.yyds.yygh.user.service.UserInfoService;
import com.yyds.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户列表（条件查询带分页）")
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pages = new Page<>(page,limit);
        IPage<UserInfo> pageModel =  userInfoService.selectPage(pages,userInfoQueryVo);

        return Result.success(pageModel);
    }
    @ApiOperation("锁定")
    @PutMapping("/lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId ,
                       @PathVariable Integer status){
        userInfoService.lock(userId,status);
        return Result.success();
    }
    @ApiOperation("查询用户详情")
    @GetMapping("/show/{userId}")
    public Result show(@PathVariable Long userId){
        Map<String, Object> map = userInfoService.show(userId);
        return Result.success(map);
    }
    @ApiOperation("用户认证审批")
    @GetMapping("/approval/{id}/{authStatus}")
    public Result approval(@PathVariable Long id,
                           @PathVariable Integer authStatus){
        userInfoService.approval(id,authStatus);
        return Result.success();
    }

}
